package com.alibaba.nacos.naming.core.v2.event.service;

import com.alibaba.nacos.common.notify.Event;
import com.alibaba.nacos.naming.core.v2.pojo.Service;
import com.alibaba.nacos.naming.push.v2.NamingSubscriberServiceV2Impl;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * using by {@link NamingSubscriberServiceV2Impl}
 */
@AllArgsConstructor
@Getter
public class ServiceEvent
        extends Event {
    private final Service service;

    public static class ServiceChangedEvent
            extends ServiceEvent {
        public ServiceChangedEvent(Service service) {
            this(service, false);
        }

        public ServiceChangedEvent(Service service,
                                   boolean incrementRevision) {
            super(service);
            service.renewUpdateTime();
            if (incrementRevision) {
                service.incrementRevision();
            }
        }
    }

    @Getter
    public static class ServiceSubscribedEvent
            extends ServiceEvent {
        private final String clientId;

        public ServiceSubscribedEvent(Service service,
                                      String clientId) {
            super(service);
            this.clientId = clientId;
        }
    }

}
